﻿using EntityModels.Entities;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EntityModels.DbContexts
{
    /// <summary>
    /// 并发标记与行版本
    /// </summary>
    public class ConcurrentMarkDbContext : DbContext
    {
        public DbSet<ConcurrencyCheckEntity> concurrencyCheckEntities => Set<ConcurrencyCheckEntity>();

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<ConcurrencyCheckEntity>()
                .Property(c => c.ConcurrentMark)
                // 配置列为并发检查标记
                .IsConcurrencyToken();

            modelBuilder.Entity<ConcurrencyCheckEntity>()
                .Property(c => c.RowVersion)
                // 配置列为行版本（仅支持Microsoft SQL Server）
                .IsRowVersion();
        }

    }
}
